import java.util.*;

class Person{
    private String id;

    public Person(String id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return Objects.equals(id, person.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}

public class test {


    public static boolean containsNearbyDuplicate(int[] nums, int k) {
        HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
        for(int i=0 ;i< nums.length;i++){
            int num = nums[i];
            if(map.containsKey(num)  && i - map.get(num) <= k){
                return true;
            }
            map.put(num,i);
        }


        return false;
    }


    public static void main(String[] args) {
        containsNearbyDuplicate(new int[]{1,0,1,1},1);
    }
    public List<String> topKFrequent(String[] words, int k) {
        HashMap<String,Integer> map = new HashMap<>();

        //首先计算每个单词出现的次数,存在map键值对中
        for (String s:
             words) {
            if(map.get(s) == null){
                map.put(s,1);
            }else{
                int val = map.get(s);
                map.put(s,val+1);
            }
        }

        //找前k个最大的value值的单词，建立小根堆
        PriorityQueue<Map.Entry<String,Integer>> minheap = new PriorityQueue<>(new Comparator<Map.Entry<String, Integer>>() {
            @Override
            //以value值为依据建立小根堆
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                if(o1.getValue().compareTo(o2.getValue()) == 0) {
                    return o2.getKey().compareTo(o1.getKey());
                }
                return o1.getValue().compareTo(o2.getValue());
            }
        });

        //遍历map
        for (Map.Entry<String,Integer> entry:
             map.entrySet()) {
            if(minheap.size() < k){
                minheap.offer(entry);
            }else{
                //后size-k进行比较
                Map.Entry<String,Integer> top =  minheap.peek();
                if(top.getValue().compareTo(entry.getValue()) < 0){
                    minheap.poll();
                    minheap.offer(entry);
                }else if(top.getValue().compareTo(entry.getValue()) == 0){
                    if(top.getKey().compareTo(entry.getKey()) > 0){
                        minheap.poll();
                        minheap.offer(entry);
                    }
                }
            }
        }

        ArrayList<String> list = new ArrayList<>();

        for (int i = 0; i < k; i++) {
            Map.Entry<String,Integer> tmp = minheap.poll();
            list.add(tmp.getKey());
        }

        Collections.reverse(list);
        return list;
    }

    public static void main2(String[] args) {
        HashBuck2<Person,String> hashBuck2 = new HashBuck2();
        hashBuck2.push(new Person("1234"),"wht");
        hashBuck2.push(new Person("1234"),"shiniao");

    }
    public static void main1(String[] args) {
        HashBuck hashBuck = new HashBuck();
        hashBuck.push(1,15);
        hashBuck.push(1,117);
        hashBuck.push(11,1);
        hashBuck.push(4,11);
        hashBuck.push(14,1170);
        hashBuck.push(7,1);
        hashBuck.push(111,1);
        hashBuck.push(16,2);
        hashBuck.push(166,3);
        hashBuck.push(76,4);

    }
}
